s = 'mavgfeyvzdgi'
def longest_nondecreasing_substring(s):
    #if s is None or len(s) <= 1:
        #return s

    longest = test = s[0]

    for i in range(1, len(s)):
        if ord(s[i]) >= ord(s[i - 1]):
            test += s[i]
        else:
            if len(longest) < len(test):
                longest = test
            test = s[i]
    if len(longest) < len(test):             #easy to miss
        longest = max(longest,test)
    return longest
print(longest_nondecreasing_substring(s))
print(s[::-1])